package com.ctshk.rpc.order.goods.mapper;

import com.ctshk.rpc.order.goods.base.CustomBaseMapper;
import com.ctshk.rpc.order.goods.dto.CommoditySpecifications;
import com.ctshk.rpc.order.goods.entity.CommodityCostAttribute;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 商品成本表属性 Mapper 接口
 * </p>
 *
 * @author 姜斌文
 * @since 2021-04-13
 */
public interface CommodityCostAttributeMapper extends CustomBaseMapper<CommodityCostAttribute> {

	@Select("SELECT t.id,t.commodity_attribute_id,t.commodity_id,t.specifications_attribute_one_id,"
			+ "t.specifications_attribute_one_name,t.specifications_attribute_two_id,t.specifications_attribute_two_name,"
			+ "t.gmt_create,t.create_id,t.gmt_modified,t.modified_id,t.is_deleted "
			+ "FROM `ctshk-goods`.t_commodity_cost_attribute t "
			+ "WHERE  t.is_deleted = 0 AND "
			+ "t.commodity_id = #{commodityId} AND t.commodity_attribute_id = #{commodityAttributeId}")
	List<CommodityCostAttribute> findCostAttributeByCommodityIdAndAttributeId(
			@Param("commodityId")Long commodityId, @Param("commodityAttributeId")Long commodityAttributeId);

	/**
	 * 查询商品属性集合
	 *
	 * @param id
	 * @param id1
	 * @return
	 */
	@Select({
			"SELECT id,commodity_attribute_id,commodity_id,specifications_attribute_one_id," +
					"specifications_attribute_one_name,specifications_attribute_two_id," +
					"specifications_attribute_two_name,create_id,modified_id,is_deleted,gmt_create,gmt_modified " +
					"FROM `ctshk-goods`.t_commodity_cost_attribute " +
					"WHERE (commodity_attribute_id = #{id} AND commodity_id = #{commodityId})"
	})
    List<CommodityCostAttribute> selectAllList(@Param("id") Long id,@Param("commodityId") Long commodityId);

	/**
	 * 多规格商品信息查询
	 * @param multipleCommodityIds
	 * @param code
	 * @return
	 */
	@Select({
			"<script>" +
			"SELECT  id,commodity_attribute_id,commodity_id,specifications_attribute_one_id," +
					"specifications_attribute_one_name,specifications_attribute_two_id,specifications_attribute_two_name," +
					"create_id,modified_id,is_deleted,gmt_create,gmt_modified  " +
					"FROM `ctshk-goods`.t_commodity_cost_attribute     " +
					"WHERE (commodity_id IN " +
					"<foreach collection=\"list\" item=\"id\" index=\"index\" open=\"(\" close=\")\" separator=\",\">\n" +
					"#{id}\n" +
					"</foreach>" +
					" AND is_deleted = #{isDeleted})" +
			"</script>"
	})
    List<CommodityCostAttribute> selectByIds(@Param("list") List<Long> multipleCommodityIds,@Param("isDeleted") Integer code);


	/**
	 * 查询规格
	 * @param specificationsNameId
	 * @return
	 */
	@Select("SELECT t.id, t.specifications_name_id, t.specifications, t.is_deleted FROM `ctshk-goods`.t_commodity_specifications t WHERE t.is_deleted = 0 AND t.specifications_name_id = #{specificationsNameId}")
	List<CommoditySpecifications> findBatchSpecificationsByNameId(Long specificationsNameId);
}
